# Contributor: Galen Abell <galen@galenabell.com>
# Maintainer: Galen Abell <galen@galenabell.com>
pkgname=khal
_pyname=$pkgname
pkgver=0.10.5
pkgrel=0
pkgdesc="CLI calendar application build around CalDAV"
url="https://lostpackets.de/khal"
arch="noarch"
license="MIT"
options="net"
depends="
	python3
	py3-atomicwrites
	py3-click
	py3-click-log
	py3-configobj
	py3-dateutil
	py3-icalendar
	py3-tz
	py3-tzlocal
	py3-urwid
	py3-xdg
	"
makedepends="py3-setuptools py3-setuptools_scm py3-sphinx py3-sphinxcontrib-newsfeed bash"
checkdepends="py3-pytest py3-freezegun vdirsyncer"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	"
source="https://files.pythonhosted.org/packages/source/${_pyname%"${_pyname#?}"}/$_pyname/$_pyname-$pkgver.tar.gz"

build() {
	python3 setup.py build
	make -C doc man PYTHONPATH="$PWD"
	for shell in bash zsh fish; do
		PYTHONPATH="$PWD" _KHAL_COMPLETE=${shell}_source python3 ./bin/khal >khal.$shell
	done
}

check() {
	# skip locale tests
	# many tests are flaky: https://github.com/pimutils/khal/issues/860
	# test_import_from_stdin doesn't work in docker: https://github.com/pimutils/khal/issues/683
	local skip_tests="
		not test_vertical_month_unicode \
		and not test_vertical_month_unicode_weekdeays \
		and not test_vertical_month_unicode_weekdeays_gr \
		and not test_vertical_month_abbr_fr \
		and not test_multi_uid_vdir \
		and not test_event_different_timezones \
		and not test_birthdays \
		and not test_birthdays_no_year \
		and not test_birthdays_29feb \
		and not test_import_from_stdin"
	pytest -v -k "$skip_tests"
}

package() {
	python3 setup.py install --prefix=/usr --root="$pkgdir"
	install -Dm644 doc/build/man/$pkgname.1 "$pkgdir"/usr/share/man/man1/$pkgname.1

	install -Dm644 khal.bash \
		"$pkgdir"/usr/share/bash-completion/completions/khal
	install -Dm644 khal.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_khal
	install -Dm644 khal.fish \
		"$pkgdir"/usr/share/fish/completions/khal.fish
}

sha512sums="
f7b1e4d4934757ec7458fc4e73c6b6c5ee6b1c64f6cdc3e61771a2f05041515e4afb73b4a17cbc577747039b689ddd66503e120648c4bfe4e33113a3de6f3d14  khal-0.10.5.tar.gz
"
